package gui.lesson04;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class TestImageIcon extends JFrame {
    public static void main(String[] args) {
        new TestImageIcon();
    }
    public TestImageIcon(){
        //获取图片的地址
        JLabel jLabel = new JLabel("TestImageIcon");
        //获取TestImageIcon文件class类中同级目录下getResource的资源
        URL url = TestImageIcon.class.getResource("tx.jpg");
        ImageIcon imageIcon = new ImageIcon(url);
        jLabel.setIcon(imageIcon);
        jLabel.setHorizontalAlignment(SwingConstants.CENTER);
        Container container = getContentPane();
        container.add(jLabel);
        setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.pack();
        setSize(600,600);
    }
}
